they already sell appliances that do that. Daikin Altherma line, for example, can combine A/C, sanitary hot water and home heating.
In summer it takes heat from the inside of your house an puts it in the water tank. In winter, it takes heat from the air in the atmosphere and puts it both inside your home and water tank.