You are correct that global energy isn't conserved. But it is actually worse than that.
Since energy is frame dependent and there isn't necessarily a global frame, then there isn't even an objective number called total energy that can change from moment to moment.
So there just isn't a thing called total energy.
And energy isn't free, to get some energy you have to interact and choosing to interact with something will have opportunity costs and will change the other thing for instance depriving future generations or others now from getting what they could have.
For instance if you saw a shell of matter contracting about you, then you could get some springs and let the shell compress the springs and then use that energy to power some rockets to head off in many directions. But the "mass" of the shell as seen from far away didn't change while it compressed.
When you had the springs the "mass" as seen from far away of the shell plus springs did not change as the shell compressed the springs. But as you take that energy and use it to send the rockets out then each region the rockets go past start to see less "mass" for the things left behind.
So to distant people they saw a group of shells and springs and rockets that had an overall mass that didn't change. And then when you sent that energy out they see an overall mass that is smaller. So it is like mining, there was some available resources and now there is less available resources.
This is the opposite of free energy.
Now let's look at expansion. If two galaxies are already moving apart you could try to attach a spring to them, but these are two entire galaxies I'm not sure how you expect to do this.
But what if someone did that in the past and now the two galaxies are moving towards each other. If the springs (or what not) were removed then you just have two galaxies moving towards each other. This time you want to extract local energy from that. Well you can.
Andromeda is heading towards the Milky Way right now, there is possibility to get some energy from that.
The heat death is about useful work versus heat. That means that heat is (roughly) a natural way for energy to flow from high entropy regions to low entropy regions (really it is from high temperature to low temperature). If you just let things mix then you might expect the low temperatures to increase and the high temperatures to decrease until it is hard to get this natural flow of energy anymore. The heat death is about the uniform temperature. And it is a losing battle if energy is naturally flowing from high temperature to low temperature and even when we do work that makes energy flow from one low temperature thing to another higher temperature thing that even more energy ends up picking on some other things.
It is like your air conditioner. The inside of your house gets colder but you just made the outside even hotter by more than you cooled your house (when measured in energy transfer). Now you and your neighbors live in a hotter environment, it is a losing battle.
Now there are complications. Gravitationally bound systems can have a negative heat capacity if they can expand, so the outer layer of a star might get colder (and larger) when heat from the hot core rushes to it. This can cause the star to swell (our sun will do this and grow so large that we get destroyed as the outside of the sun gets colder but much much closer).
So you can get energy. It isn't free. And energy will still naturally flow from hot to cold and fighting that is a losing battle overall.
I'm not sure what you misunderstand.