I wouldn't recommend it in a 40g - there's a possibility it could work out, but it's risky.
If the pistols are opposite genders, they'll pair up, and if not one may wind up dead.
As for the gobies, typically different species will harass each other if confined to a small space. Neither of the species you mentioned is especially aggressive, but auroras get pretty large.