emiller is right, dogs do crazy things to jockey for the alpha position in the house.
A good place to start (if you are gone during the day) is on days you don't work. Leave home for short periods of time and return. Maybe she has separation anxiety the Vet can treat that for you with medication.
Chihuaha owners have told me their little friends get cold quite easily. for this reason, they typically sleep next to their people.
When you leave for work, try to make sure the temerature is comfortable for her. And leave her a few toys near the place she goes to sleep when she is alone.
At night, when she snaps at you, remain calm. Because of her size be very careful with her. What you will do first is say, "NO" . Then Gently roll her on he back place your hand around her snout (Don't squeeze), just hold her firmly in place. Attach a command to this action. A good one (that you will remember also) is, "relax" spoken softly but in a firm tone. Eventually most dogs eventually do relax every muscle in their body when this training is done. Have a treat to give her when she finally relaxes it is difficult to predict what she will do the first time. If she hops back up to nip at you, repeat this. Hopefully she will learn to be the good girl you see in the morning all the time.
I had a Cocker Spaniel with Rage disorder my Vet advise I do this training and this worked for me.
Good luck with your little girl. At 5 years old, she may have some bad memories to work with. But with patience, she will be fine.