I am not a plumber, these are suggestions/ideas for you to research further, not 'advice'.. You should fit non-return valves inline between (a) the cold feed to the water heater and the heater inlet (b) the hot water pipe coming from the hot water tank. The simplest way would be to fit two stopcocks...