Press and hold the sleep/wake button, and slide to turn the power off. Once the phone is turned on again, check if you can restore or update the device.
Restart your computer and your modem.
Each time you get any kind of error, make sure to update iTunes to the new version. If that does not help, remove the software from your computer, and install the latest version.
You need to check if your security settings are the issue and if the firewall is blocking the connection. That may be the reason why the error appeared.
If your antivirus program is outdated, that may be the problem. Make sure to update it to the latest available version. If that does not help, turn the program off until you are done with the restore or update, or simply uninstall it from your computer.