Taillights sometimes work, then they both go out, and come back

The TS switch is where the TS/ brake function are split from each other, being they use the same filament on the 1157 bulbs
Yes, but the OP stated his brake, turn, and flashers work as expected. Only the parking/ tail lights are an issue. That the brake, turn, and flashers work says the ground at the bulbs is good.

The park/ tail lights comes directly from the headlight switch, with power to the switch coming from the tail stop fuse so that shows the fuse and power into the headlight switch MAY not be the problem,