Poor earths, low battery power, dirty contacts inside the lights and switches, bad contacts between bulbs and lgiht contacts, poor fuse connection .. all sorts of potential problems, it's mostly a case of working through each one and eliminating each light or door switch connection ..
As they stay solid unless the engine is running I'd also check the alternator and it's earth and battery connection.