In this paper, an optimal energy management scheme for building microgrids with rooftop greenhouse is proposed. A building energy management system (BEMS) is utilized for the optimal fulfilment of energy demands in the building and the greenhouse. The exhaust heat generated due to the operation of air conditioners in the building is used for fulfilling the cooling demands of the greenhouse via chillers. In addition to thermal and cooling demands, the four major control parameters (temperature, humidity, light intensity, and CO 2 concentration) are also considered for optimal growth of crops in the greenhouse. A multi-agent system (MAS) is adopted to realize the interaction among several households of the building, the greenhouse, and the BEMS. The MAS comprises of several inner-level, intermediate level, and upper-level agents, which are responsible for their respective tasks. The performance of the proposed optimization strategy is evaluated for two seasons of a year, i.e., summer and winter. Numerical simulations have demonstrated the effectiveness of the proposed operation scheme for optimal operation of building microgrids with rooftop greenhouses.