You can gain energy in several ways, one of which is simply staying online. Every 30 minutes, you will receive 20 energy, which you can see just below your mana and life bars, like this: . Currently, there is a limit of 5,000 energy (10,000 if you have a Premium Account). You can also obtain energy by completing quests and daily quests (as long as they are not on cooldown), where the amount varies depending on the quest level—the higher the level, the more energy it will grant. Any gathering action in any profession will consume 5 energy. You can increase this energy consumption along with the profession relic, which can be obtained either through crafting or by purchasing it in the Blue Diamonds store.
Although it is possible to gather various resources without energy, it is advisable to gather while having energy, as it provides a 50% bonus on collected materials, while not having energy will result in a -50% penalty.