Did Madara use Izanagi or Izanami and if yes then how did he have two Rinnegans? If someone uses Izanagi their sharingan gets destroyed right? If he used Izanagi then he should have only one sharingan left and then that evolved into Rinnengan. How does he have two Rinnengans?
Spoiler alert for if you haven't finished the manga or anime
Madara used the Izanagi to cheat death (just like I said in the comment section). The second part that I said was wrong. When he was fighting Hashirama he bit off a part of his (Hashirama's) arm, then after his "death" he vomited up the piece of flesh and implanted it into his wounds, which let him activate the Rinnegan (in both eyes).
You should remember that Hashirama is Ashura's reincarnation and Madara is Indra's (Ashura and Indra are The Sage of Six Paths' children), which is the reason why he was able to awaken it (Rinnegan) in the first place.
The Rinnegan can typically be awakened by gaining Hagoromo's chakra either by reproducing it from combining the chakra of Hagoromo's sons, Indra and Asura, or by directly receiving chakra from Hagoromo himself.
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.
So he didn't awaken the it right away. (The other part of your question is also answered above).
- Naruto volume 71: I Love You Guys
He sealed the Izanagi in his eye before the battle meaning that if he died it would activate and bring him back, so in theory he could have used his old Sharingan before he gained the eternal mangekyo, after all we saw Danzo do that having a sharingan in his arm to sacrifice rather than the one he had in his head. So why can't madara have done the same.
The Mangekyō Sharingan's usage and activity place a great strain on the user themselves, wearing at the user's body and causing deterioration to their vision until eventually over-usage leaves them blind.
As is case with Izanagi. Izanagi in same way takes away ordinary mangekyo Sharingan.
Their vision can be restored by receiving the transplanted Mangekyō of an Uchiha with strong blood ties — ideally a sibling — thus awakening so-called Eternal Mangekyō Sharingan. The Eternal Mangekyō merge the designs of the transplanter and the transplantee's original Mangekyō. Their Mangekyō-based abilities are made stronger and they ** no longer suffer any negative side-effects from the usage**. According to Madara, the Eternal Mangekyō Sharingan is proof an Uchiha continues to seek something despite experiencing great losses.
So, Madara had eternal mangekyo Sharingan which he never after Izanagi. Thus, he could have Rinnegan in both his eyes.