Water companies are to undertake thousands of actions totalling £22 billion in investment to improve the environment, under a programme agreed with regulators.