Your energy bar has 270 energy points at the beginning. Using tools and the fishing rod drains energy from you, even if you miss the mark. The scythe and weapons do not draw energy from you when you use them, so you can always defend yourself if you are being attacked.
Passing Out From Exhaustion
Eating and sleeping can recover your energy, but do not use up all of your energy or you will pass out. As soon as you reach zero energy, you become exhausted and can only move slowly. You will see a popup that tells you that your character is tired.
At this point you can still use tools, but once you reach -15 energy you will pass out. At that moment the day ends and if you passed out outside your home, you also lose 10% of your money (up to 1,000 gold!). After passing out, you will only be able to regenerate half of your energy.
Energy From Sleeping
If you go to bed before 0:00 AM, you will regenerate all of your energy. Going to sleep exhausted or by passing out, you will only get half of the energy back.
If you go to sleep after midnight, you will get less and less energy back in 10-minute steps. At 2:00 AM you will pass out.
So it's best to always go to bed before midnight, that way nothing can go wrong in Stardew Valley!
Increase Your Maximum Energy
At the beginning of the game, the maximum energy per day is always limited to 270 points. However, by eating Stardrops you can increase your energy to the maximum of 508 energy points.
A Stardrop gives you 34 energy points permanently and you can find a total of eight of these fruits. You have to do different things for each fruit. The Stardew Valley Wiki has a list of all Stardrop locations.