A novel model predictive control (MPC) framework is proposed to optimize the energy management of integrated rooftop greenhouses and buildings, aiming to reduce control costs and the likelihood of climate violations. The centralized intelligent control approach employed for both the integrated rooftop greenhouse and the building ensures optimal conditions for crops and occupants. The integrated rooftop greenhouse utilizes waste heat and air from the building, resulting in reduced energy and CO2 consumption. The nonlinear dynamic models of temperature, humidity, and CO2 concentration for integrated rooftop greenhouse climate and building are first constructed. An integrated optimization problem is then formulated to acquire the optimal control decisions. The proposed MPC framework is implemented to regulate temperature, humidity, and CO2 level via controlling fans, pad cooling, shades, heating, ventilation and air conditioning systems, CO2 injection, and lighting systems. The indoor climate of an integrated rooftop greenhouse on a building in Brooklyn, New York, is controlled for the case study to show the advantages of the proposed nonlinear model predictive control framework. The results show that the average energy savings from the building to the integrated rooftop greenhouse amount to 15.2 % with the integration of the i-RTG and the host building under the proposed MPC framework.