I have a 2002 Nissan Altima and the heater blows out cold air most of the time. It occasionally blows out hot air but doesn’t seem to have any rhyme or reason to it. The a/c did the same thing in the summer. When they work the hot air is great and same with the cold on the a/c.
The first thing to do is make sure the engine cooling system is full of coolant. Check the radiator when it’s cold and make sure it’s full. If there’s an air pocket in the cooling system it can cause loss of interior heat.
I think, however, you’re having a problem with the blend door in the HVAC system. The blend door controls air temperature by directing incoming air through either the heater core or the AC evaporator (or both) depending upon the desired temperature.
If the blend door is sticking, or moving when it shouldn’t, you won’t get the air temperature you want.
Some HVAC systems are electrically controlled and some operate by vacuum. I’m not sure which is the case on your Altima, but a shop that specializes in automotive cooling and HVAC systems can probably diagnose and repair the problem pretty quickly.
My wife’s 2004 Maxima does the same. Heat (or AC) work fine while driving, but don’t blow heated (or cooled) air while idling. Very suspicious.