How should I fix this?

i have a puppy he goes outside but will play he sometimes goes pee and poop out there but often i will stand for 5-10 mins and he doesn’t go so i go back in and he poops or pees in the floor and i get so annoyed i yelled at him and felt bad i have done it only a few times but i also have the issue of he is teething and bit me and my nephew so i spanked him on the butt he did it again and grabbed my throat lightly it didn’t hurt but i stopped him again and he did it again and again and the final time he actually bite down and his tooth cut my skin so i pinned his head down and told him to stop he stopped but after i feel guilty and bad cause he is so nice but he keeps not listening and how else can i correct him cause he won’t listen otherwise and i am sad rn will my puppy still love me

How should I fix this?
Post Opinion