Yes, あいだ and とき can be used, and are commonly used there. The meanings/nuances are almost the same in that sentence, but of course there are differences in meanings/nuances and usages among them. For example, while in the sentences AうちはB and AあいだはB, A must have a time length, like a state or an on-going action, AときはB can be used also when A is a moment/point of time.
e.g.
〇電車が動いているうちは、降りてはいけません。
〇電車が動いているあいだは、降りてはいけません。
〇電車が動いているときは、降りてはいけません。
(電車が動いている is an on-going action.)
〇電車が駅に着いたときは、雨は降っていなかった。
×電車が駅に着いたうちは、雨は降っていなかった。
×電車が駅に着いたあいだは、雨は降っていなかった。
(電車が駅に着いた is a moment.)
There are other differences between うちに and あいだに, あいだ and あいだに, とき and ときに and ときは, etc., but it's a bit complicated, as you guessed.