In this study, we develop a novel nonlinear model predictive control (NMPC) framework for climate control of buildings with renewable energy systems to minimize electricity costs. A nonlinear dynamic model of the building climate and renewable energy systems, including temperature, humidity, thermal comfort, geothermal heat pump, and solar panels, is first constructed based on mass and energy balance equations. The nonlinear dynamic model is then integrated into the proposed NMPC framework, which iteratively solves a nonlinear programming problem to generate the optimal control inputs, which minimize energy consumption and carbon footprints for sustainability. A simulation case study on controlling a building located on the Cornell University campus is conducted to demonstrate the capability of renewable energy sources to reduce building energy consumption using the proposed NMPC framework. The results show the NMPC framework could efficiently minimize total electricity cost and constraint violation for thermal comfort to 12.9 % with no more than 0.2 of violation on the predicted mean value index in different seasons. Implementing an electricity storage component could reduce the electricity cost by 19 %. The results indicate better sustainability for the smart building using sustainable energy sources and the NMPC framework.