Sounds like a ground issue.
Clean all battery cables on at a time.
There's supposed to be a ground post behind the driver's side kick panel, clean the wires grounded there.
You are referring to changing the speed sensor on the rear differential, right?