A method for converting ammonia in wastewater into nitrogen gas while simultaneously generating power in a bioreactor system. This method produces energy from carbon and nitrogen waste and provides significant cost and energy savings over current options. Using bacteria in carefully controlled aerobic and anoxic reaction phases the organisms in the bioreactor convert ammonia into nitrite in a first stage at an extremely low dissolved oxygen level and subsequently convert nitrite into nitrous oxide gas in a second anoxic stage through either biotic or abiotic mechanisms. The nitrous oxide can then be decomposed exothermically into nitrogen and oxygen by passing it over a heated catalyst bed or burned with methane resulting in direct energy generation from the waste nitrogen. The bioreactor outputs clean nearly nitrogen-free water and heat that can be used to produce power.