Freeze rotation on local axis

Is it possible to do this via script? If so, how so?

Are you talking about freezing the rotation of a specific axis?
If you are using an rigibody you can accomplish that pretty easily by modifying restraints