A model predictive control (MPC) framework is developed in the present study, with the final objective to improve the energy flexibility of building thermal loads through demand-side management. Three different configurations are tested and tuned, with the following objective functions: minimizing the delivered energy to the building, the electrical energy used by the HVAC system (heat pump) or the cost of this electricity use. To validate these MPC configurations, a Matlab-Trnsys co-simulator is also created, in order to run the MPC on a virtual plant composed of a detailed building model. The MPC strategy manages to run effectively on the chosen study case (a residential building with heat pump in Spain), and the differences between configurations are discussed.