Window unit air conditioners suck in air from outdoors, cool it and blow it indoors. When outdoor temperatures fall below 60 degrees Fahrenheit, the incoming air can actually freeze inside the unit. The compressor lines circulate the coolant, so any already-cool air that comes into contact with them can form frost or even ice. The compressor is located on the outdoor section of the unit -- just in front of the condenser -- and this area is usually quite warm. Check the forecast before bed and turn off the air conditioner if the weather is supposed to turn chilly overnight.
If airflow through the unit is blocked in any way, the cooled air becomes trapped inside the unit and circulates inside, causing frost and ice buildup. Use a dry paintbrush or compressed air to remove dust and dirt from the condenser and evaporator coils, then change or wash the air filter according to the manufacturer's instructions. Clean the vents and air filter regularly to keep this from happening. Remove any outdoor unit covers or indoor curtains that could potentially block airflow.
Similar to blocked airflow, a broken fan traps the cool air inside the unit, allowing frost to form. If you hear the motor running but no air comes out of the unit, a broken fan motor is likely the issue. This is a job for a professional for two reasons. First, some fan issues can be resolved with minor but skilled electrical tinkering. Second, if the fan motor needs to be replaced, the electrical aspect makes it a job for an experienced pro. If your air conditioner is still under warranty, check your paperwork to see if the fan motor is covered before contacting a repair person.
If your window unit is rather elderly, it may just be low on coolant. Contrary to common sense, low coolant levels can lower the temperature of the cold parts in the unit. Since the compressor lines circulate the coolant, they are a prime target. This is another job for pros because coolant is restricted to those with special permits in most places. Even if your unit is relatively new, you could have a leak somewhere in the path of the coolant that would reduce your levels quickly. A professional will check for leaks before refilling the coolant.