How to assign role to user who is an employee using server side script and hooks.py

when an employee is created then a user is being created based on the employee record by using the create user button in employee doctype

now when the user is being created, i want to assign role and module profile to the user, so how can i do it?
can i write a server side script which will trigger(using doctype events) when a user is being created and check if there is already an employee record with the user mail and if does then assign a role and module profile to the user
how can i use hooks.py file for this, i mean how can i trigger the script using hooks.py ?