You need to make sure that your dog is getting an adequate amount of exercise before you leave it for a period of time.
Consider a 15 to 20 minute walk, fetch session, or playtime as an absolute minimum.
Beyond the puppy stage, most dogs will function - and behave - best with about and hour and a half of physical activity each day.
When you are away, also ensure your puppy has something to do - chew toys, rawhide treats, or even their favorite slimy ball.
If it's at all possible, and your dog does not habitually bark or growl at passing people or dogs, give your dog a view so they can watch the world pass by when they can't be romping around in it.
You also need to rule out any sort of medical condition first; for example, a physical condition may be the main cause of the toilet accidents, and a neurological condition could be the real source of the anxiety, especially if it occurs at times outside of your absences.
Finally, you MUST puppy-proof your home.
This means making sure all garbage containers are sealed off and inaccessible.
Any food on your kitchen counter is cleared away (you'd be surprised at how agile dogs can be when no one is watching).
Any household items that are at risk should be put away.
There are items that you can't protect easily, such as doors and carpets.
If you do return home to find these damaged, remember that they are repairable and replaceable.
You should never punish your dog after the fact.
They will not associate the punishment with the crime.
And the fact that they may now also fear the one person they're longing for, it will make their separation anxiety much much worse.