The massive integration of renewable energy, and the electrification of the building heating systems are required in order to meet the Paris agreement’s CO2 emission target. Heat pumps and PV is expected to penetrate quickly in the market come with significant investment costs. To maximize the profit and advantage of both technologies without increasing their management complexity, novel algorithms guaranteeing close-to-optimal operations should be demonstrated. In this work, a novel heuristic control algorithm is presented. The algorithm optimizes an indicator comparing the variation of the operating cost and the generated heat. It is versatile and agnostic of the building modeling complexity. The benchmark against a mixed-integer linear formulation of the energy management shows that the proposed algorithm performs closely to the optimal solution. The differences in terms of operating costs and temperature deviations are negligible. The simplicity of the algorithm makes it suitable for implementing in a micro-controller as a state machine.