After the battle with Hashirama, Madara loses one of his eyes because of the Izanagi. He awakens only one Rinnegan eye before he dies. But when he got resurrected using Edo Tensei, he has a pair of Rinnegan eyes. Similarly, once he gets his true body back, he has Rinnegan in both eyes. How is this possible?
In the first case, Madara had a blind eye due to the Izanagi he used. But the eyesight was restored when the Rinnegan formed in both the eyes. This is because it is a characteristic quality of the Rinnegan. The wikia articles on Rinnegan and Uchiha Madara supports it:
However, Madara's Sharingan did not become Rinnegan until decades later, at the end of his natural lifespan; this also seemingly restored the eyesight lost from his use of Izanagi.
It was not until decades later, towards the end of Madara's natural life, that the cells had any effect, awakening the Rinnegan (in the process restoring his right eye).
So therefore, formation of Rinnegan completely heals the eyes.
When the Edo Tensei was used, he was revived at the prime stage of his life, along with enhancements. That explains him having having both the eyes.
Lastly, when he breaks out of the Edo Tensei, his Edo Tensei Rinnegan eyes are still intact. But after being brought back to life by the Samsara of Heavenly Life Technique, his fake Rinnegan eyes turn into dust. He fights without eyes for a while. White Zetsu brings him one of his original eyes, and later on, he steals away his original eye from Obito.