This work is settled in the area of safety-critical embedded systems and presents a formally funded approach for automatically creating an optimized task structure from a Simulink model. Based on an extended task network formalism, in a first step, a formal translation scheme on Simulink block level is defined. Because the resulting tasks are very fine-grained and unbalanced with respect to their required computation demand (denoted as task weight), in a second step, an optimized task structure is created by formally merging tasks with each other. Here, the optimization goal is to minimize inter-task communication and to balance the weights of tasks. Additionally, it is formally proven that both the translation and the merging of tasks preserves the formal execution semantics of Simulink. The whole approach was implemented as an automated tool-chain and evaluated with the help of a case study.