Hello my name is ***** ***** thank you for your question.
The first thing that comes to mind that I would check based on your description is the Alternator. It sounds like it's intermittently not charging properly which is why it's causing what you are describing. What I would do to verify this is when this starts to happen pull over open the hood and put a volt meter on the battery. Then turn the AC and rear defroster on while the head lights are on and see what the charging system voltage is reading. That is considered testing with all loads on. With all loads, it should read around 13.9 volts. With all loads off, no lights, ac or rear defrost, it should read around 14.3 volts. Intermittent charging could be a hard thing to capture if it doesn't do it very often or very long. So that is why I am saying to try to keep a volt meter with you if you have one to be able to capture this when it happens.
When the alternator stops charging the car will run off the battery. Once battery voltage gets low, systems will shut down to direct the power to try to keep the vehicle running. Like the lights and could explain why it start to run poorly. That is why I am thinking it's a Alternator issue.
When it comes to Alternators, if you do find that is your issue, I recommend getting the part from the dealer. After market alternators don't tend to work or last as well as ones from the dealer. Example. A after market alternator has a normal life span of around a year or less. Where one from the dealer could last years. But that is also why it's more expensive.
If you have any more questions on this, please feel free to ask.
If not, and you're satisfied with my help, please Rate me. That is how I get credit for my work. I hope I have provided you with Excellent Service.