How long does caffeine from coffee stay in your system? If I drink a cup at 4:00pm, will it be out of my system by midnight?

Generally yes. However some people are very sensitive to caffeine and they feel the stimulation from it for even longer. Some people can't have coffee after noon for example.
Yes but. Mist would recommend no caffein after noon. Afternoon fatigue is usually due to dehydration. Drink more water.