If someone is in the middle of shemoneh esrei and hears the chazzan saying “modim….” he should bow down [as per   the rules previously learned] , but of course not respond in any way.

If the Kohanim start bentching birkas kohanim, he should stop and just listen.

Someone learning in a Bais Medrash may put his head down and nap , if that becomes necessary as an aid to his learning.It is preferable to distance oneself from the Aron HaKodesh

Vaeschanan Bulletin