To answer your question, we must do one thing: separate organic matter from the wastewater. That way the wastewater gets recycled and the organic matter becomes energy. I think the most interesting concept to date is to use that organic waste as a source for electricity or green gas through the biomass process.
Some locations are already doing this. Take a look at this article: https://www.theguardian.com/business/2010/oct/05/human-waste-turned-renewable-gas
I carry an advanced EC unit, that recovers cellulose floc from municipal wastewater. The material is pressed into a bark and can be burned as biofuel. Contact for more info. email@example.com