Horses are herd animals, and they feel safe in a herd. That's why he gets panicky when he's away from them. When he's with them, he needs to find out his place in the herd. The pecking order. Is he low man on the totem pole, or will he be the boss. Most horses try to exert dominance until the other horse puts him in his place. He's fine once he finds his place.
It can be corrected. Keep him busy and listening to you. If you are doing groundwork and he acts up around the other horse in the arena, make him work a bit harder, changing directions, and so on. If riding, you have to keep him busy, too. Change directions, and keep him wondering what you will ask next.
He needs to learn that YOU are is herd, and that you are the boss when you are working with him, and to ignore the other horses.