I'm glad you made the connection that this is fear based, not everyone would realize that

. When he's about to bark/snarl, try redirecting him to a treat. Teach him that when a dog approaches or someone's coming to your door, he should look to you. This also helps build an association between the scary event and treats, thereby helping to make the experience more enjoyable and less scary. Work at greater distances at first, and progress to closer. Every time he experiences one of his triggers, it should be "party time", where you give him treats, get his focus off the scary thing, and make it a positive experience.
You'll probably also want to set up practice situations, instead of just waiting for them to happen.
For instance:
-Have a friend with a well-behaved (not crazy and excitable)walk their dog at the same time as you, and have the two dogs approach from opposite directions. Once the two dogs are near enough that your dog seems nervous, but is not totally gone crazy yet, signal your friend to stop coming closer. (you should stop too) Ask your friend to have their dog sniff the ground and turn sideways (they can throw treats on the ground off to the side to get this behavior)- these are dog "calming signals", which is how dogs tell each other they are not a threat. Then have your dog do a "watch me" if he knows that, and ask him to sit, or do other commands. Point is, have him focus on you. See if you can get any closer while still keeping your dog's focus. Get as close as you can that day (don't try to push it too far), and try again later or another day.
-If this is too elaborate, you could also take your dog near a dog park, and work on "watch me" and "sit" at progressively smaller distances to the park fence.
- It's the same idea with people coming to your house. Have someone approach your door, and once your dog gets nervous, have the person stop, and redirect your dog. Eventually work up to the point where people can get all the way to your door, and open it, without incident.
-The reason he calms once they come in is probably because he realizes that you are ok with the "intruder", so maybe acting very happy and excited when people approach the door would help, but that entirely depends on your specific dog, so I don't know.
-Perhaps you could also try meeting the person before they approach. (This will depend on how good your dog is with strangers outside of the home, though) Start by meeting them in the street near your house, and you all walk to your house together. Work up to starting closer and closer, until you only have to meet them when they're almost to your door, and then eventually so that all you need to do is open the door before they get out of their car, etc, until he can wait until they get inside.