Biogas production from wastewater is seen as a sustainable way to recover energy. Anaerobic digestion processes convert the organic material in wastewater to biogas, which can subsequently be converted to electricity and heat. The focus of this project is to optimize the energy recovery in an industrial wastewater treatment plant. The main objective is to study how mathematical models can be used for the description and analysis of processes, and subsequently be explored for the optimization of the reactor performance.The anaerobic digester under study is a granular sludge reactor, where the biomassis present in the form of granules. This leads to high-rate conditions and can be a challenge to model. To this end, two separate models based on the Anaerobic Digestion Model No. 1 (ADM1) were developed: i) A flow + reactor model (ModelI), reaching high biomass concentrations by recycling the biomass back into the reactor through an artificial loop, and ii) a granular model (Model II), where the reactions take place within a biofilm. Both models were calibrated with two separate datasets of three weeks each. The datasets contain extensive measurements of COD, nitrogen, sulfur and phosphorus species, as well as measurements of biogas production and mineral composition. Mass balances verified the quality of the measurements, and an influent fractionation was performed. Model I was applied for optimization of the process conditions, where it was found that lowering the pH had a positive effect on the chemical dosage to the reactor and did not lead to reduced energy recovery. This strategy was applied to the full-scale reactor. Simulation results furthermore revealed that while removing sulfur compounds from the influent increased the energy recovery, the gain was less than the removal cost. Long-term simulations were performed with Model II, where precipitation within the granules was taken into account. It was shown that precipitation can have detrimental effects on the process performance on the long-term, due to the competition for space between precipitates and biomass within the granules.The impact of an increased loading rate was one of the optimization strategies that was studied, as the loading is limited by nitrogen removal. An evaluation was made on the potential implementation of the anammox process as an alternative nitrogen removal method post-anaerobic digestion, indicating significant experimental and modelling work is still needed.