Anaerobic treatment of wastewater can produce methane and some systems recover this methane. The problem is few can do it. It takes equipment to do this and unless you have a 20 million gallon per day flow, the costs to produce out weighs the methane you get back. Even then, the methane is basically used to run the wastewater facility. That is all the energy produced.
I have made some research and I would say that it wouldn't be that easy to generate energy, specifically electricity from wastewater but there are four basic principles that can make this possible. These are:
1. Bacteria oxidize the organic matter (a.k.a. poop, milk, etc)
2. This oxidation process produces electrons
3. These electrons flow from the fuel cell’s anode to its cathode
4. This flow of electrons creates an electrical current
water has both oxygen and hydrogen. Hydrogen burns, oxygen helps. So in a way, water itself a good fuel:-d
Poop in it and then used fart powered turbines. Hope this helps.