How did Madara Uchiha survive such a long time?
Madara, when he was close to death, awakened the Rinnegan.

The Rinnegan allowed him to break the seal placed by the Sage of the Six Paths, and summon the Juubi's shell (The Gedo Mazo) from the moon.

Using it as a catalyst, Madara used Hashirama's cells in order to extend his own lifespan.

Once disconnected from the Mazo, Madara died instantly.