How does heat actually stay kept in the carbon molecules in the atmosphere? We have all learned that the earth is getting heat up because of the CO2 and CO molecules absorbing heat. However, how is heat actually kept in those molecules. When photons heat them up, their electron gets excited and goes to a higher energy level; however, we know that atoms want to remain at a low energy state and they quickly drop down to a lower energy state (correct me if I am wrong here). If that is happening, then how can heat be actually kept in a carbon-monoxide or carbon-dioxide molecule?
Is it because during the day, they get heat up and remain heated because they require more time to get to a lower energy state?
Note: This is not a duplicate to the question given as a duplicate because the other question was addressed at why is one element able to absorb heat and not the others. This question, on the other hand, is focused towards how any element is able to absorb heat at all.
 A: The greenhouse effect  is due to two mechanisms, neither of which would cause it independently. 
Mechanism 1 – insulation
Greenhouse gases are opaque to infrared light. They absorb infrared, then re-radiate it. To pass through a layer of gas like this, a unit of infrared energy does something like a random walk. It's enters the layer, is absorbed by gas, and is then re-radiated, either up or down. Up, and it escapes the layer (in to space, or back to Earth). Down and it continues on, further in to the layer, where it may be caught by another opaque molecule and need to do another up/down trial.
In this way, the gas layer acts as an insulator. As you increase the density or thickness of the layer, units of infrared energy take longer to get from one end to the other, because they need to perform more up down trials to pass through it. Infrared energy will persist where it is for longer, either at the Earth's surface, or in space.
Mechanism 2 – "creation" of infrared at the surface
The atmospheric insulating layer is only trapping infrared. It is largely transparent to visible light and ultraviolet, so visible light shines through to reach Earth's surface.
Some of the visible light that makes it to Earth is reflected back as visible light and radiates away unhindered in to space. However, much of it is absorbed by Earth, warming it up.
Earth then re-radiates the absorbed energy back out, but not with the original spectrum. Instead, the radiated energy is mostly in the infrared portion of the spectrum *.
Because the atmospheric layer is an infrared insulator, a unit of infrared light tends not to escape out in to space, but instead, persists at the Earth's surface being re-abrobed and re-emitted. I should note: heat will, with a random walk, eventually exit the atmosphere. Insulation just means it takes longer to escape. The better the insulation, the longer each unit of warmth persists at the surface.
Summary
The atmosphere is an insulating blanket. This would keep Earth as cool as it keeps it warm. However, because the blanket only works on infrared energy, visible light shining on Earth gets to "beam through" the blanket and "make" heat at the Earth's surface on the "inside" of the blanket.
Increasing CO2 (and other infrared opaque gases) in the atmosphere thickens the blanket. The thicker the blanket, the longer a unit of heat persists at the surface, leading to a rise in temperature.
Caution
The mechanism of the greenhouse effect was first speculated on in 1896. 
Modern climate science considers many more factors and mechanisms than this kind of extremely simplified model, but I am not familiar with them. Deniers / sceptics frequently seize on potential first order approximation mechanisms to try to reject the climate change hypotheses. Sceptical Science is a great source for intensely detailed analysis of common misconceptions.

* The reason that Earth radiates infrared, where as the sun's radiation has a significant visible component, is that while both can be thought of as black body radiators, Earth is very much cooler than the sun, so has a low frequency dominated spectrum.
A: 
We have all learned that the earth is getting heat up because of the CO2 and CO molecules absorbing heat.

@Benjohn has given you the correct answer. Here is my take.
The ultimate heat provider of the earth ( except a small percentage of heat from the magma at the center of the earth) is the sun. It pours down at the surface about 1.2 kilowatts of energy per meter square ( which btw  is directly used by solar panels). The same energy falls on the surface of the moon whose surface burns up during its daytime and freezes by black body radiation at night.
The earth is fortunate to have a gas atmosphere which mitigates the extremes of the possible temperatures that the ground would reach otherwise. An example of mitigation is what happens at the sea floor. Most of the energy is picked up by the water and the floor is kept at a steady temperature with small changes day and night in the first meters from the surface, depending on the season, radiating away with the black body radiation, but the body of water has such large heat capacity that variations are small.
The gas atmosphere is a more temperamental "blanket", its heat capacity depends on several gases , called green house gases from the bad impression that agricultural green houses work that way ( they do not, they work by inhibiting heat exchange by convection   but that is another story, on which there is no controversy).
The main green house gas is water , H2O.  It is worth contemplating this figure :


Solar irradiance spectrum above atmosphere and at surface. Extreme UV and X-rays are produced (at left of wavelength range shown) but comprise very small amounts of the Sun's total output power.

We see that H2O has the most absorption spectrum for infrared wavelengths, (which are the wavelengths of heat )and then comes CO2. Green house gases absorb both incoming and reflected from the surface of the earth infrared, and as most of the reflected wavelengths are in the infrared they act as a slowing down of the black body radiation that would finally leave the earth. As a blanket keeps a person warmer green house gases by playing ball with infrared radiation ( the wavelengths where heat is really transferred) keep the surface of the earth into a reasonable temperature for life, lucky us.

However, how is heat actually kept in those molecules. When photons heat them up, their electron gets excited and goes to a higher energy level; however, we know that atoms want to remain at a low energy state and they quickly drop down to a lower energy state (correct me if I am wrong here).

Heat is kept collectively when kept, it is not a one atom thing but emerges statistically by the response of zillions of atoms which keep  on exciting and deexciting by collisions and vibrations etc as described in the other answers.

If that is happening, then how can heat be actually kept in a carbon-monoxide or carbon-dioxide molecule?

Heat is not kept in an individual molecule but in the gas ensemble but in a sense the level of green house gases have a delaying action in the radiation of the earth to the atmpsphere, by reflecting back and forth with the surface. This keeps the temperature  close to the surface from fluctuating enormously between daytime and night ( as on the  moon), it is a buffer similar to the buffer of water for the floor of the ocean.

Is it because during the day, they get heat up and remain heated because they require more time to get to a lower energy state?

No, it is a collective emergent thermodynamic phenomenon as I said.  No need to invoke atoms and quantum mechanics at the level of heat.
Now going back to the figure, the reason so much stress has been put on anthropogenic CO2 is because of computer modeling of the dynamics of the atmosphere. The atmosphere is not a static phenomenon, it has winds, interacts with ocean surfaces, has storms etc. The models assume that CO2 increases act as a trigger for the land and atmosphere to release more H2O, in a feedback mechanism, and thus  be pivotal in contributing  to the small increase in temperature since the middle of last century, but this is another story.
A: In the atmosphere, molecules such as CO$_2$, CO, H$_2$O, O$_3$ and CH$_4$ absorb infrared light due to vibrational energy transitions while homonuclear diatomic molecules such as O$_2$, N$_2$ and H$_2$ and monoatomics such as He, Ne, etc. do not.  
To absorb a photon by transition of vibrational quantum level there needs to be a way for the molecule to change dipole moment by vibration.  This is why the monoatomics and homonuclear diatomics do not absorb infrared light in the atmosphere. 
Electronic transitions from the ground state are of higher energy, and are not in the infrared range.  Electronic transitions are not responsible for the absorption of heat radiated from the Earth's surface, which is primarily in the infrared range.
The molecules and atoms in the atmosphere are constantly colliding.  These collisions distribute energy among the molecules and atoms.  The molecule that absorbs the infrared light does not "keep" the energy to itself, it is rapidly transferred to the other molecules and atoms in the atmosphere.
A: Take a look at the Wikipedia "Greenhouse Effect" page.  Put simply,  start with  photons emitted from the Earth's surface skyward.  CO2 molecules absorb some of these photons.  When the molecules re-radiate photons, they do so isotropically, meaning uniformly in all directions.  This means that a large fraction of the energy which originally was headed for Spaaaaaace!  is now aimed back at the Earth or perhaps at the rest of the atmosphere.  The net effect is to reduce the amount of energy removed from the Earth+atmosphere system.
A: Carbon dioxide has several strongly resonant energies where infrared light can be converted into vibrations and rotations of the carbon and oxygen atoms, in addition to their electronic excitations. This mechanical energy gets transferred to other atmospheric molecules during collisions, where it gets partitioned among rotational, vibrational, and translational degrees of freedom. The translational motions — the gas molecules are moving with some speed — are what we usually consider when we talk about the temperature of a gas, because that's how a gas interacts most efficiently with its surroundings.
Methane, with one carbon and four hydrogens, is much more efficient at converting infrared light into mechanical energy because there are more ways for it to vibrate at any given energy.
A: It is mainly because of the Greenhouse Effect.
The idea is that thermal equilibrium is achieved when the amount of heat that reaches the Earth from the Sun equals the amount of heat radiated by the Earth.
Now, the heat from the Sun comes in a broad spectrum of frequencies, from infrared to ultraviolet. The Earth atmosphere is transparent to a great deal of it. Some is absorbed in the atmosphere, but most of it heats the soil and the oceans.
But the heat radiated from the Earth is in form of thermal radiation, that is, infrared radiation. And here is the problem: CO2 and other GH gasses are opaque to infrared radiation, so this radiated energy cannot escape to the space, and the point of thermal equilibrium goes up the themometer.
Yes, the CO2 molecules in the atmosphere will heat and themselves will radiate in infrared, and some of that energy will eventually go to the space, but it will be far less that what would scape if the CO2 were not there in the first place. Remember that the amount of radiated energy increares with the temperature, and the CO2 in the atmosphere is quite colder than the soil or the ocean.
If you want to feel the Greenhouse Effect yourself, just park your car for a few hours under the Summer sun (glass is transparent to light but opaque to infrared, just like CO2). You'll note that the interior of the car is far hotter than the street. The usual remedy is to put a reflective surface under the windows, so that the sun energy is reflected to the outside as visible light. Or leave the windows opened, so that the hot air can flow out the car.
A: The answers already given are excellent, however there is something missing that I think needs to be explained. If we step back from the detailed physics given in the other answers, we have this picture. The Earth aborbs per unit time some energy from the Sun and it will radiate this energy back into space. If we then add greenhouse gasses and wait until the atmosphere has settled down and a new equiliubrium is reached, then it seems that nothing has changed. The Earth still absorbs the same amount of radiation per unit time and that same amount must be radiated back into space. So, how come that the temperature on the ground has increased?
As explained in the other answers, the greenhouse gasses will absorb and then re-radiate the thermal radiation. The emitted thermal radiation will be according to the local temperature in the atmosphere. If you look at the photons that escape to space and consider where they come from, then you'll see that the more greenhouse gasses you add the higher up in the atmosphere these photons will come from (on average and this depends on the frequency of the photons).
So, while the emitted amount of radiation into space stays the same, this radiation will on average come from higher up in the atmosphere. However, the emitted radiation is thermal radiation and this thus depends on the local temperature in the atmosphere and the higher we go the colder it becomes. This then means that in the new equilibrium situation, the temperature at ground level must have increased.
