It's pretty difficult to troubleshoot wiring problems on vehicles sometimes. All the suggestions thus far are very good ones.
Once the op determines if it is the tow vehicle or the trailer using a test plug that has been mentioned, then checking all the wiring for shorts or loose connections. Hopefully the op's problem will be a simple plug problem, and not have to resort to total rewire of the trailer like I had to do.
My particular fifth wheel ended up being the wires on the trailer, where they actually are routed through the axles to the brakes on the side opposite the harness. The wires had chafed and shorted to the axles intermittently causing the errors very similar the the op's experience. I ended up replacing the entire harness with heavier gauge wires which were recommended by many who had similar issues. It seems that manufacturers sometimes don't use heavy enough gauge wires in the brake harnesses, probably to save money. I also did not route the wires through the axles as the manufacturer had done. I strapped the wires to the outside of the axles and I used 12 gauge extension cord which has thick insulation to prevent shorting in the future.
There are several threads with photos showing how to do all this.