Formation of planetary systems from pebble accretion, migration and dynamical instabilities