It could be a couple things that cause this problem. The most common would be a door switch as when you open the door the lights come on and when closing they go off. If the switch is acting up it can cause this. Also a head lamp switch can cause the lights to do this. To know for sure you need get the lights acting up and check with a volt meter or ohm meter.
If you still need help just reply, if not click ACCEPT when we are done.
Yes to both questions. This can happen when sitting still or driving and any mechanic will know how to use a meter.