The networksetup utility is the program OS X uses to change the network configuration. The Network Preference Pane in system preferences is just a front end to networksetup; networksetup can do everything the preference pane can do (and possibly more).
The parameters you are interested in (from the man page):
-getwebproxy networkservice
Displays Web proxy (server, port, enabled value) info for <networkservice>.
-setwebproxy networkservice domain portnumber authenticated username password
Set Web proxy for <networkservice> with <domain> and <port number>. Turns proxy on. Optionally, specify <on> or <off> for <authenticated> to enable and disable authenticated proxy support. Specify <username> and <password> if you turn authenticated proxy support on.
-setwebproxystate networkservice on | off
Set Web proxy on <networkservice> to either <on> or <off>.
-getsecurewebproxy networkservice
Displays Secure Web proxy (server, port, enabled value) info for <networkservice>.
-setsecurewebproxy networkservice domain portnumber authenticated username password
Set Secure Web proxy for <networkservice> with <domain> and <port number>. Turns proxy on. Optionally, specify <on> or <off> for <authenticated> to enable and disable authenticated proxy support. Specify <username> and <password> if you turn authenticated proxy support on.
-setsecurewebproxystate networkservice on | off
Set SecureWeb proxy on <networkservice> to either <on> or <off>.