Has he been to the vet to rule out any medical issues? That should be first, as it could be an UTI that he cannot control, and that discomfort could also be affecting his mood ...