The aim of this paper is to enhance the results of the graphical approach for Heat Pump (HP) integration in non-continuous processes. A nonlinear programming (NLP) formulation is developed which optimizes temperature levels of condensation, evaporation, and storage temperature layers in order to further reduce total annual cost (TAC) and greenhouse gas (GHG) emissions. In addition, the NLP formulation requires low computation time given the practical approach. By its application on an AMMIX butter production of a large dairy factory, it is shown, that the temperature differences in the condenser and evaporator are reduced sharply which improves the COP of the HP from 2.2 to 3.4. As a result, the TAC can be reduced by an additional 16,721 NZD/y and the GHG emissions by an additional 29 tCO2/y in comparison to the graphical approach.