Derp is an expression of stupidity, or a brief loss of the ability to form a coherent sentence, thus it is spoken.
Herp is another form of derp and is normally placed before derp in the form of "Herp derp." An "a" can be added in between to form "Herp-a-derp," which means the same as herp or derp.
It can also be used as a response to when someone says something incredibly stupid, or it can be said by someone who realizes something he or she said was dim witted.
Any other uses from this is improper. Herp, Derp, and Herp-a-Derp should be used in moderation and properly so that it doesn't get bothersome.