I am a EU citizen so I am not sure about you situation. For freelancing you need to go to Gewerbeampt and "sign in" (anmelden) as developer. Then go to finanzampt and ask for a steuernummer. If you want to freelance outside of Germany ask for a Umsatzsteuernummer also. I hope this helped. If you have more questions inform me.