In buildings having both a heat pump and a district heating connection installed, the operation of the two heat sources can be optimized by an energy company to reduce system costs and in many cases reduce emissions from the heating of the buildings.