Integrated Task and Motion Planning (ITMP) for mobile robots in a dynamic environment with moving obstacles is a challenging research question and attracts more and more attentions recently. Most existing methods either restrict to static environments or lack performance guarantees. This motivates us to investigate the ITMP problem using formal methods and propose a bottom-up compositional design approach called CoSMoP (Composition of Safe Motion Primitives). Our basic idea is to synthesize a global motion plan through composing simple local moves and actions, and to achieve its performance guarantee through modular and incremental verifications. The design consists of two steps. First, basic motion primitives are designed and verified locally. Then, a global motion path is built upon these certified motion primitives by concatenating them together. In particular, we model the motion primitives as hybrid automata and verify their safety through formulating as Differential Dynamic Logic (d$\mathcal{L}$). Furthermore, these proven safe motion primitives are composed based on an encoding to Satisfiability Modulo Theories (SMT) that takes into account the geometric constraints. Since d$\mathcal{L}$ allows compositional verification, the sequential composition of the safe motion primitives also preserves safety properties. Therefore, the CoSMoP generates correct plans for given task specifications that are formally proven safe even for moving obstacles. Illustrative examples are presented to show the effectiveness of the methods.