Commercial and residential buildings consume more than 40% of the total energy in most countries, and HVAC (Heating Ventilation and Air Conditioning) systems typically consume more than 50% of the building energy consumption. A recent study  indicates that optimal control of HVAC system can achieve energy savings of up to 45%. Therefore, optimized control of HVAC system can potentially reduce significant amount of energy consumption globally. Demand response (DR) is becoming an important mean to reduce peak energy consumption and balance energy demand and supply. Hence, optimal control of building's HVAC system as a DR may not only reduce energy cost in buildings, but also reduce energy production in grid, stabilize energy grid and promote smart grid. In this paper, we describe a model predictive control (MPC) framework that optimally determines control profiles of the HVAC system as demand response. A Nonlinear Autoregressive Neural Network (NARNET) models the thermal behavior of the building zone and the optimal control problem is formulated as a Mixed-Integer Non-Linear Programming (MINLP) problem. The optimal control objective minimizes the total energy costs of powering HVAC system and the corresponding GHG emission considering dynamic demand response signal, on-site energy storage system and energy generation system while satisfying thermal comfort of building occupants within the physical limitation of HVAC equipment, on-site energy storage system and on-site energy generator.