I'm not sure Ivan would necessarily have wanted to get rid of Sophia - at least not in the short term. She had been a big support to their brother Fyodor, and also, as Ivan would still have been only 15/16 when he became Tsar he probably would have been glad of her experience. However as he grew in confidence as a ruler he might have started to resent any attempts Sophia might have made to dominate him, and to at least "encourage" her to take a back seat, if not necessarily a return to the Terem.
Re Ivan's relationship with Peter, I think that if Ivan proved himself to be a healthy and half way competent Tsar then, as the lawful successor to his elder brother, he probably wouldn't have viewed Peter as much of a threat. Also, as Peter was about six years younger than Ivan, by the time he was coming to manhood, Ivan would probably be married and with a young family - thus guaranteeing the succession. If Peter started to show himself ambitious for the crown, then Ivan might have had to take steps to curb him, but provided Peter remained loyal he might have felt glad to have had such a dynamic brother who could perhaps carry out certain duties that Ivan himself didn't have the time or the inclination to do.