Yorkshire Water has been forced to pay out £40 million to address failings over wastewater and sewage by regulator Ofwat.