How corals produce oxygen when there is no sun?

Algae consume oxygen, but usually much less than was produced during the daylight. Algaes can reduce the amount of oxygen a bloom produces without reducing its nighttime oxygen demand. Extremely calm or cloudy days may reduce photosynthesis and oxygen production.

They still stay alive though even there is no sun because of storms?

Corals live long and photosynthesis just stop when there is no sun. They depend on the nutrients stored on their body.