I have a basenji mix rescue that I adopted when he was 5 months old. I recognize many of the behaviors you describe. Amazingly, after he turned 1 year old, it was like a switch flipped and he was much better so there may be hope for your pup as well. Cody is 3-1/2 now and only recently have I felt like he recognizes me as HIS human. 2 things which I found to be helpful was Dr. Karen Overall's relaxation protocol. You can download a pdf file here:
https://www.boulderhumane.org/sites/default/files/ProtocolforRelaxation.pdf
And recently I began giving him a Zuke's calming treat (ordered from Amazon) before leaving him at home and the occasional potty mistakes have disappeared.
He's extremely food motivated so that has helped a lot as well as what others have mentioned about routines. A friend told me that dogs learn how to be dogs from other dogs. He has a pack of regulars at the park and I think that has helped, too.