Answer: The Shulchan Aruch (YD 244:1) writes that there is a mitzva mideoraisa to stand for a talmid chacham or anyone over seventy. R’ Ovadia Yosef (Yechave Daas 3:70) writes that if one isn’t sure if one is seventy yet, they need to stand regardless, following the rule of safek deoraisa lechumra, that we are strict with regards to doubts of Torah laws.
The Shulchan Aruch (YD 244:11) writes that if a talmid chacham walks in while one is learning, one should interrupt their learning to stand up for them. The Aruch Hashulchan (YD 244:7) explains that this is no different to other mitzvos which one is supposed to interrupt their learning for.
The Mishna (2:1) and Shulchan Aruch (OC 66:1) discuss when one can interrupt during shema and its surrounding berachos for important reasons. The Magen Avraham (66:1) and Mishna Berura (66:2) write however, that this doesn’t really apply nowadays, and we don’t interrupt the shema to speak to anybody.
R’ Eliezer Waldenberg (Tzitz Eliezer 14:10), however, writes that the reason that one who is learning should stand is because one should be able to do so without properly interrupting their learning. Nonetheless, he writes that while one should stand during their davening, one shouldn’t if they are reciting the shema.
Nonetheless, R’ Moshe Sternbuch (Teshuvos Vehanhagos 4:22) writes that one should stand even while saying the shema especially as it is unlikely that it will stop one’s concentration (See Shevet Halevi 6:146:4). Similarly, the Ben Ish Chai (Ki Seitzei 2:15) writes that as honouring a talmid chacham is essentially honouring Hashem, one should stand even in the middle of the shema.
In conclusion, one must stand up when a Rav or elderly person passes them even if one is davening and even while saying the shema providing it won’t disturb them.