The adoption of stricter effluent requirements by the European Union rises large problems for small communities having few economical and technical resources. These problems motivate the synthesis of advanced optimisation-based controllers in order to enhance the performances of small-size wastewater treatment plants. The aim of this study is to develop a methodology of dynamic optimisation and optimal control of small-size alternating aerobic-anoxic activated sludge plants. The first part deals with the improvements which can be potentially obtained through the application of dynamic optimisation techniques. Two problems are considered: the minimisation of nitrogen discharge and the reduction of the operating costs. These are constrained, non-convex and high-dimensional problems that exhibit hybrid discrete/continuous and combinatorial behaviour. In both cases, the application of the resulting optimal aeration strategies leads to large improvements of the process performances, while satisfying the discharge requirements and the operating constraints; it is also verified that the long-term implementation of the optimal control profiles guarantees durable process improvement. The embedding of the optimal aeration strategies within closed-loop controllers is dealt with in the second part of the thesis. Optimal control consists in (i) the on-line joint observation/estimation of both state variables a nd parameters and, (ii) the use of a non-linear model predictive control scheme to update the aeration profiles. Beforehand, a reduced model is derived by simplifying the general ASM~1 model and sensitivity analyses are performed to quantify the influence of unmeasured disturbances and model mismatch on the optimisation results. Numerical implementations show that the resulting closed-loop controller brings large improvements with respect to usual operating modes either in terms of nitrogen discharge or in terms of energy consumption.