The mishna says that one is allowed to extinguish a candle out of fear that the goyim will catch him on their holiday. The gemara explains that even according to R. Yehuda who says that a melacha she'eina tzricha l'gufa is assur, it is permitted (not just patur) for the sake of pikuach nefesh. Rav Moshe (Dibros Moshe #72) raises a very interesting question. What gives him the right to light in the first place? How can someone light candles on erev shabbos knowing that it is a holiday and therefore dangerous to have candles burning so that he will need to extinguish the flame on shabbos?
In perek Rebbi Eliezer D'mila (shabbos 134) the Ran cites a famous machlokes between the ba'al hameor and the ramban. In a situation where one needs warm water to bathe a child after a bris, and doesn't have warm water, can they do the bris now knowing that they don't have water, but then rely on the pikuach nefesh need of the child to heat up water on shabbos after the Bris. The Ba'al Ha'meor holds that one is not allowed to put himself into a situation where he will have to violate shabbos for a pikuach nefesh need. Rather, we push off the bris. But the Ramban takes a באשר הוא שם approach and says that right now he is obligated to perform the mitzvah of milah which pushes off shabbos. Even if afterward he will have to violate shabbos for pikuach nefesh, so be it. It would seem that according to the Ramban it is obvious why we can allow him to light candles erev shabbos even though he realizes that he will have to violate shabbos by extinguishing the flame when it becomes a pikuach nefesh concern, because we judge the situation at the moment.
Although one can argue that even the Ramban will only allow a bris which itself is such a significant mitzvah that it pushes off shabbos, but who says the Ramban will allow one to light candles if they know that they will need to extinguish the flame for pikuach nefesh? Rav Moshe proves from the Ba'al Hameor that the Ramban will maintain his באשר הוא שם position even for a less significant mitzvah like lighting candles. The Ba'al Hameor proves that one pushes off the bris from the mishna in beitza that one must push off the mitzvah of simchas yom tov and not shecht an animal if they know that after the shechita they will have to rely on the mitzvah of kisuy ha'dam pushing off yom tov. What is the proof? Maybe bris which is significant enough to push off shabbos is allowed to be done, but other mitzvos such as simchas yom tov cannot. Clearly, even the ba'al hameor understands that if we are to permit the activity based on the fact that now we aren't required to worry about what it will lead to, we can permit any activity. Therefore, the Ramban who holds that one can do a bris knowing it will lead to violating shabbos for pikuach nefesh, would also allow lighting candles knowing that it will lead to violating shabbos for pikuach nefesh.
However, according to the Ba'al Hameor, the question remains. How can we allow this person to light candles to begin with?
I would like to answer this based on the steipler. The Ba'al hameor himself allows one to get onto a boat for a mitzvah purpose right before shabbos, even though he knows he is putting himself into a situation of chilul shabbos for pikuach nefesh. Why then does the ba'al hameor require the pushing off of the mitzvah of milah? The Steipler explains that the Ba'al Hameor holds that before shabbos one is not required to abstain from an activity that will lead to chilul shabbos. But, on shabbos one is not allowed to do anything that will lead to pushing off shabbos for pikuach nefesh because we regard it as if he is beginning the violation of shabbos right now, even before the pikuach nefesh situation arises. Therefore, before shabbos you can get on the boat, but on shabbos you can't do the bris (or get onto the boat). Based on this, even the ba'al hameor will allow the lighting candles before shabbos knowing that the flame will need to be extinguished for pikuach nefesh, since it is being done before shabbos.