An optimized heat pump control for building heating was developed for minimizing CO 2 emissions from related electrical power generation. The control is using weather and CO 2 emission forecasts as input to a Model Predictive Control (MPC) -a multivariate control algorithm using a dynamic process model, constraints and a cost function to be minimized. In a simulation study the control was applied using weather and power grid conditions during a full year period in 2017-2018 for the power bidding zone DK2 (East, Denmark). Two scenarios were studied; one with a family house and one with an office building. The buildings were dimensioned on the basis of standards and building codes. The main results are measured as the CO 2 emission savings relative to a classical thermostatic control. Note that this only measures the gain achieved using the MPC control, i.e. the energy flexibility, not the absolute savings. The results show that around 16% savings could have been achieved during the period in well insulated new buildings with floor heating. Further, a sensitivity analysis was carried out to evaluate the effect of various building properties, e.g. level of insulation and thermal capacity. Danish building codes from 1977 and forward was used as benchmarks for insulation levels. It was shown that both insulation and thermal mass influence the achievable flexibility savings, especially for floor heating. Buildings that comply with building codes later than 1979 could provide flexibility emission savings of around 10%, while buildings that comply with earlier codes provided savings in the range of 0-5% depending on the heating system and thermal mass.