In this paper, we address energy management for heating, ventilation, and air-conditioning (HVAC) systems in buildings, and present a novel combined optimization and control approach. We first formulate a thermal dynamics and an associated optimization problem. An optimization dynamics is then designed based on a standard primal-dual algorithm, and its strict passivity is proved. We then design a local controller and prove that the physical dynamics with the controller is ensured to be passivity-short. Based on these passivity results, we interconnect the optimization and physical dynamics, and prove convergence of the room temperatures to the optimal ones defined for unmeasurable disturbances. Finally, we demonstrate the present algorithms through simulation.