I am not sure if I can justify WHY using "which" is more formal. From experience you are much less likely to hear preposition + which in casual conversation or informal writing, and you are more likely to hear where, when, why.
Switching which and where, when, why depends mostly on the style and structure of the rest of the sentence. Again, a formal or informal tone could make one a better option. I cannot think of any cases that truly cannot be changed.
My favorite month is February, in which we celebrate President's Day.
My favorite month is February, when we celebrate President's Day.
The first sentence is a little clumsy and overly formal, and you are more likely to hear the second one.
Yesterday I visited the park where I first learned to play baseball.
This tone is again casual and much better suited to "where" than "in which."
The company president gave a speech in which he announced there will be layoffs.
A layoff, losing a job, is quite serious. "In which" works quite well with the no-nonsense tone.