In a world facing increasing environmental and energy challenges, anaerobic digestion of agrifood by-products and food waste could contribute to the production of green energy while reducing greenhouse gas emissions into the atmosphere. Anaerobic digestion is a biological process capable of breaking down and stabilising organic matter in the absence of oxygen and converting it into a renewable source of energy, known as biogas. Biomethane production also enables the generation of electricity and produces digestate, a by-product of the digestion process that can be used as a soil conditioner or fertiliser. This review aims to highlight how substrate pretreatment, together with the optimisation of operating parameters, application of additives, recirculation of digestate and frequent feeding, can increase biogas production. An overview of the basics of the anaerobic digestion of agrifood by-products and food waste is provided, including feedstock characteristics (nutrient content, particle size and inhibitory compounds) and process parameters (process configuration, pH, temperature, total and volatile solids, total Kjeldahl nitrogen, ammonium, chemical oxygen demand, carbon/nitrogen ratio, retention time, organic loading rate, etc.). In addition, recent studies in the field of processes, equipment and pretreatments that can significantly improve the anaerobic digestion process of agricultural and food wastes were classified and discussed. Finally, the challenges and future perspectives of biogas production from the agrifood sector are addressed.