An aerobic environment is characterized by the presence of free oxygen (O2) while an anaerobic environment lacks free oxygen but may contain atomic oxygen bound in compounds such as nitrate (NO3), nitrite (NO2), and sulfites (SO3). Aerobes are microbes that require O2 as their terminal electron acceptor, but anaerobes use a bound form of oxygen instead. There is by definition a byproduct of anaerobic decomposition -- the non-oxygen element must go somewhere when the oxygen atom is biochemically removed by the microbe. When sulfites are present, the byproduct is hydrogen sulfide, a foul smell corrosive gas. When nitrites/nitrates are present, the byproduct is inert nitrogen gas.
Most microbes in wastewater are facultative. That is in the presence of oxygen they act as aerobes, and in the absence of oxygen they act as anaerobes even if bound oxygen is present in large amounts. Why is aerobic respiration favored? The biochemical pathway using O2 provides a much higher oxidation/reduction potential and is energetically favored