I think the problem of "energy" is a tough one to solve because often what we mean by "energy" isn't what we think. I find it's easier to think about what we're trying to do. If my goal is to write more quality code, then this is actually a function of more than just my energy.
The problem is that the line between these factors is somewhat blurred. Energy influences focus, and motivation influences both focus and energy. Lack of knowledge can sometimes feel like lack of focus. etc.
- Knowledge - Energy - Focus - Motivation
The last one, motivation, is the biggest wild card for me. It can be the source of huge productivity. When I feel motivated, it's almost like a 2x or 3x modifier to energy and focus.
There are days when I have energy, and I can focus, but I just don't feel motivated to work on programming... even if, I want to. I often describe this as, "I want to want to work". In other words, I want to work, but I'm just not feeling it at all. I'll generally read a book or something in those instances.