but would it still work if he was away from it?
Of course. The container, when used as a merchant container, is just to store the data which will appear in the merchant menu. If you kill the NPC, you will not get any of the items from the container. It would also be wise to hide the container somewhere, where the player can't get, or to lock it with a key. You see, if the player raids the container, the NPC won't have anything to sell