This falls under the generic umbrella of taking care of yourself. Take breaks, eat and sleep well, exercise... These all help with energy levels and mood.
Another one that was very helpful for me is to find a hobby you really enjoy outside of the field of your work. For years all I did for hobby and work was programming. It got me really far, really quickly in my career but I burnt out hard one year. Even though I thought I was enjoying myself the whole time. So I picked up music, drawing, reading (non-tech)... All helped me disconnect and get better. Doing things a little bit every day will see surprising gains.