You can restrict calls going outbound from a line or phone by changing it's Calling Search Space (CSS) - i.e. to one which includes only emergency numbers.
You can restrict calls coming inbound to a line in a number of different ways via CUCM dial plan configuration, including
- Add the line to a Partition with a restrictive "Time Schedule" configuration
- Add a Translation Pattern that matches the line's number, and either modifies the called number to the voice mail system or is set to "Block this Pattern"
An application could modify these settings programmatically via the AXL SOAP API:
Cisco DevNet: Administrative XML (AXL)