Floating ports and noisy power are 2 BIG reasons for PICs to go crazy. Set your tris registers and Ports in your code to a known state and tie unused pins to VSS or VDD through 10k resistors. Put a .01uf and a 10uf capacitor across the power lines as close to the pic as possible to short the noise there, even a ferrite bead in series with the B+ is helpful too.