Explaining it in detail is more extensive than I thought so I just got this screenshot and maybe it'll help.
As you can see I am producing energy from pops and I do have some fallen empire buildings but they're really not needed as I could just sell more of my excess food and consumer goods. Not a giant empire either.
It is also worth mentioning that this doesn't always work all game. Especially early game food is very important for growth and expanding your empire drains all the resources from your producing worlds. But at some point you start to outproduce the cost by so much that you'll have more and more surpluses.