Swarms are highly robust systems that offer unique benefits compared to their alternatives. In this work, we propose a bio-inspired and artificial potential field-driven robot swarm control method, where the swarm formation dynamics are modeled on the basis of Markov Random Field (MRF) optimization. We integrate the internal agent-wise local interactions and external environmental influences into the MRF. The optimized formation configurations at different stages of the trajectory can be viewed as formation "shapes" which further allows us to integrate dynamics-constrained motion control of the robots. We show that this approach can be used to generate dynamically feasible trajectories to navigate teams of aerial robots in complex environments.