In this paper, we adopt stochastic geometry theory to analyze the optimal macro/micro BS (base station) density for energy-efficient heterogeneous cellular networks with QoS constraints. We first derive the upper and lower bounds of the optimal BS density for homogeneous scenarios and, based on these, we analyze the optimal BS density for heterogeneous networks. The optimal macro/micro BS density can be calculated numerically through our analysis, and the closed-form approximation is also derived. Our results reveal the best type of BSs to be deployed for capacity extension, or to be switched off for energy saving. Specifically, if the ratio between the micro BS cost and the macro BS cost is lower than a threshold, which is a function of path loss and their transmit power, the micro BSs are preferred, i.e., deploy more micro BSs for capacity extension or switch off certain macro BSs for energy saving. Otherwise, the optimal choice is the opposite. Our work provides guidance for energy efficient cellular network planning and dynamic operation control.