After seeing 599 how could no one see Rin's death contributing to him being bad? The guy was obsessed with her and then hearing of her death probably gave him hatred towards kakashi, much like sasuke's hatred towards the leaf. Ofcourse, this wont be the only reason he is doing what he is doing, there will be other reasons.
I think Madara found Obito, or had been watching him and saved him from the crushed rock. After years of training and seeing the truth Obito decided to help Madara take out the leaf, but also has his own revenge in mind. I have no idea how Madara died, maybe he let Obito kill him? Or someone else did?