The tail lights turning off is normal behavior when the brake lights come on.
First suspect is the yellow box, which is the tail light failure sensor module. These things do bad things when they get wet and corroded. Is the "tail light out" light lit on your dashboard?
After that, it's wiring, but most likely still in the trunk area... Assuming that you've checked that both #1157 lamps in the driver's side tail light assembly are good.