The operation of wastewater treatment plants is challenging for many small communities for economical and technical reasons. In this work, optimal control of the aeration system is considered to improve the efficiency and reliability of the activated sludge process, with application to an industrial alternating activated sludge (AAS) treatment plant. Two problems are formulated: the first one deals with the minimization of nitrogen discharge and the second one addresses the minimization of the energy consumption. In either cases, special emphasis is placed on the long-term behavior of the treatment plant in order to ensure that the optimal aeration strategies are safe and durable from the process point of view. Their solutions show that significant improvements can be achieved with respect to the current aeration strategy, with reductions up to 37% for the first problem and around 27% for the second one. Large performance improvements are also obtained when comparing the optimal aeration strategies to a conventional oxygen-based controller.