Generating energy from waste and residues