how could the Earth possibly be losing the same amount of energy as it gains?
The thing is, that there must be an energy balance, if we assume steady state. That is a simple thermodynamical law:
$$\Delta U_{internal}=E_{in}-E_{out}$$
Consider $U$ the internal energy - meaning, all energy contained in the planet in either of the forms you mentioned and including energy stored in chemical bonds as well as thermal energy, i.e. temperature.
- Under stable steady state conditions, $\Delta U=0$ (no change). This means that whatever energy is sent away from Earth i.e. as electromagnetic radiation, $E_{out}$, necessarily equals all energy the planet absorbs, $E_{in}$.
- If suddenly more energy reaches us, that extra absorbed energy will cause $\Delta U>0$, meaning that it must be stored in some way in the planet - either as some sort of chemical energy for example (chemical bonds again, more biological matter and fuel generated), or perhaps as thermal energy (higher temperature).
- If suddenly less energy reaches us, the planet would be expelling more energy than it receives, which necessarily means that energy is lost from somewhere - most commenly lost thermal energy, a drop in temperature.
Now, since chemical changes (and nuclear changes and other energy-absorbing processes) are slower than a thermal energy absorption, we will expect a temperature change whenever the thermodynamical law is unbalanced.
A key thing to note here is that any matter with a temperature radiates energy away, given by Stefan-Boltzmann's law:
$$P=A\epsilon \sigma T^4$$
$\epsilon$ and $\sigma$ are constant, the $A$ is exposed surface area and $T$ the temperature. $P$ is the power (energy per second) sent off from any object with this temperature. Your own body, any object in your house and the entire planet itself sent off energy as electromagnetic radiation at this rate. The hotter, something gets, the more energy is looses per second - the faster it cools down.
So an imbalanced thermodynamical law, with i.e. more energy absorbed than expelled, will have the temperature increased until as much energy is expelled as is absorbed. If this balance has not yet been reached, the process is heading towards it. This is simply a necessity of this energy balance.
Therefor the Earth must necessarily loose as much energy as it gains - otherwise the Sun would heat up our globe more and more and more, year by year. Until the planet's temperature would be high enough to expel energy at the same rate as it receives it. And that is the state we are at, after billions of years of adjustments of the temperature.
A word on global warming
While billions of years in stable Sun-orbit have stabilized the temperature of the planet (the Sun is our main energy contributor), with only astronomically insignificant temperature changes due to seasons and ice ages now and then, there are certain aspect of the Earth's appearance and atmosphere that may change this stable temperature.
One such aspect is the planet's albedo. The albedo is the amount of impacting energy that is absorbed. The Sun sends us a more-or-less constant amount of energy every second (the solar constant). But not all of that energy is absorbed. An icy, white planet will reflect much more than a black planet. Allowing for large portions of ice caps to melt away would therefor theoretically reduce the albedo, allowing for more absorbed energy, thus increasing $\Delta U$, which in turn would increase the temperature. A negative cycle.
Another aspect is the ability of gasses in the atmosphere to absorb energy. CO2 is a popular buzzword, but also simply water vapour and gasses like methane in the atmosphere will absorb an amount of incoming sunlight and reflect a larger portion of it back out. This sounds good at first - energy is prevented from arriving to the surface. But remember that the planet's surface irradiates energy as well, due to Stefan Boltzmann's law: And that irradiation from underneath the atmosphere will of the same argument be trapped instead of sent off from Earth. This "duvet" or "cover" is gives us the greenhouse effect, which is essential for life as we know it.
A third aspect is energy stored chemically in matter in the planet. This energy is already contained here and is already included as internal energy $U$, in the form of biological matter, fossil fuels etc. Releasing it thus shouldn't change $U$ and shouldn't interfere with the energy balance. But, if that chemically stored energy is released and converted into something else, such as thermal energy, or if it is released while allowing for the contamination of the atmosphere with more of the above-mentioned gasses, then it still will have an indirect impact by raising the overall temperature.
Many other natural and untouchable events on Earth can severally interrupt with the energy balance, such as volcanic eruptions releasing enormous amounts of gasses into the atmosphere, sudden releases of large amounts of algae in the oceans which also releases large amounts of gasses, or such as simple cloud coverage that will theoretically interfere with the albedo.
Etc...
How much these global-warming factors influence the temperature is a tough task to answer due to the high complexity of especially the atmosphere and climate. And how much we humans contribute to this, compared to when we weren't here and it was only volcanic eruptions, ice ages and the possibly mass extinctions of biological life now and then that could severally alter the climate, is the hot topic of modern political discussion.
But regardless of who or what is to blame, and regardless of how much, the answer to your main question of
How is it possible that the earth has the concept of energy equilibrium: the same amount of energy comes in and out?*
is simply that if more energy was absorbed than released, then that energy would have to be either stored or used as a temperature increase. Since the storing is not that quick (it requires large-scale biological energy conversation for example), the temperature would be impacted. Since this has been going on for billions of years already, we would expect the temperature to have already settled and been balanced. And this is where we are now, with only our minor temperature changes left to deal with, which are insignificant compared to events throughout the lifetime of the Earth.
It may seem odd and counterintuitive that the planet right now sends out just as much energy per second as we receive - within astronomically insignificant error - but it simply must be the case if we trust in thermodynamics.