It looks like you can't do this in a single CSV as the Username template field only appears if Upload type is "Add new only, skip existing users" or "Add all, append number to usernames if needed":
If you select "Add new and update existing users" to enrol both existing and new users into courses then you can't use template values. Instead you would need to do two separate operations:
- Upload a CSV with new users only and specify template "%-f_%-l". The CSV must have no username field. The site cron should then email the password to the address specified in the email field.
- Upload a CSV with existing users only to enrol these. This CSV would have a username field.
If the Moodle site can access an external database containing user details maybe you could use either core plugins (e.g. Database enrolment) or additional plugins to manage this. Or maybe you could write your own plugin.