Closed ecosystems extract energy through self-organized nutrient cycles