The Torah (Vayikra 19:32) says, “Mipnei Seiva Takum V’Hadarta Bifnei Zakein.” This verse teaches that one must stand before our elders and talmidei chachamim. The Shulchan Aruch (Y.D. 244) rules that one must stand for elders once they have reached the age of seventy. (See Chida on Shulchan Aruch who cites the view of the Ari z”l that one must stand before elders once they reached the age of sixty)
If one does not know the exact age of the elderly person he must stand in accordance with the rule of sfeika d’oraysa l’chumra, one must be strict when a doubt arises involving Biblical law. (See Yechava Daas 3:70)
The poskim debate whether one must stand before an elderly woman. For practical halacha a rav should be consulted. (See Sefer Chassidim 578 and Shevet Halevi 2:114)
One should stand for the elderly when they are within four amos away. And as soon as the elderly person passes by, one is permitted to sit down. (Shulchan Aruch 244:2)
One must stand before the elderly even if one is in middle of learning. (Shulchan Aruch Yorah Deah 244:11)
The Tzitz Eliezer (1:14) discusses whether one must stand up if a zaken (older person) passes before him while one is davening. He concludes that while he is reciting pesukei d’zimra, aleinu, karbanos etc. one must stand. However, while he is reciting Shema he should not stand up. However, many poskim, including the Chida, Rav Yosef Chaim Zonnenfeld zt”l, and the Chazon Ish, all maintain that one should stand before the elderly even while reciting Shema. (See Ishei Yisroel page 204 note 85 for a brief discussion)
The Rama (Yoreh Deah 244:1) writes that one should stand for an elderly person even if he isn’t wise in Torah as long as he isn’t a wicked person (“rasha”).
The poskim discuss whether one must stand before non-observant elders today, who desecrate Shabbos and do not adhere to halacha. On the one hand, since they are not observant of halacha, they might be hallachically classified as “rashaim”. On the other hand, since (in most situations) their lack of observance is due to a lack of knowledge and not in order to rebel against Hashem, they are not qualified as “rashaim” in halacha. They are rather classified as “tinokos shenishbu bein hanachrim”.
According to Harav Wosner zt”l (Shevet Halevi 9:198) and ybc”l Harav Nissan Karelitz shlit”a (Kibud Vehidur page 447) one need not stand up before modern day non-observant Jews, who desecrate Shabbos and do not adhere to halacha. However, according to Harav Elyashiv zt”l one needs to stand before these elders as well.For practical halacha, a rav should be consulted. However, if not standing up will cause the elder embarrassment or a chillul Hashem one should absolutely stand up.