Buildings account for about 40% of total energy use in the United States, according to the U.S. Department of Energy. Consequently, there has been a growing interest in green buildings, i.e., energy-efficient buildings, particularly control strategies for their HVAC systems. In this paper, we present a receding-horizon supervisory control strategy for optimizing total electric cost, which is the sum of an energy usage cost and an infinity-norm-like demand charge. The controller utilizes an optimizer to minimize an objective function whose evaluation involves simulation of the building energy system. This paper also presents a Matlab toolbox we developed for co-simulation and simulation-based optimization with the building energy simulation software EnergyPlus. The toolbox was applied to a benchmark example showing the potential of the proposed controller.