The conservation of mass and energy means that energy can be changed to matter and mass into energy but the total of potential energy stored in matter and active energy remains constant.
In nuclear fusion the amount of matter becomes smaller, resulting in a huge release of energy.
In a chemical reaction like the formation of water, the mass of the reactants equals the mass of the products.
The potential energy of the hydrogen and oxygen molecules is greater than the potential energy of the water (hydrogen oxide).
The heat energy released is equal to the loss of potential energy .