The earpiece represents both an figurative and, apparently, actual connection between the Agent programs and the Matrix mainframe. You can see at multiple points in the movie, an Agent will receive information from their earpiece directing them where the humans are. They also likely receive orders the same way.
(In "real" computer programming the earpiece might be implemented as a socket or a message pipe, something like that.)
Inside the Matrix universe, it's how the Agents can appear to know things they can't possibly know, without arousing the suspicions of the plugged-in humans. When a homeless guy sees someone escape the Matrix through a phone, an agent blocks away immediately finds out because the Matrix tells him in his earpiece.
From a beneath-the-Matrix perspective, it appears that the earpiece is the only direct connection the Agents have to their controlling program. When Smith removes his earpiece, he's disconnecting himself from the Matrix just a little bit. Partly, this may be just to avoid distraction, but it's also symbolic -- he's sick of the Matrix and wants it to go away, and he's about to do something that is probably counter to his orders. So he's separating himself as much as possible from the Matrix.
Note that, when the other Agents come in to get Smith during the rescue attempt, one of them notes his earpiece is out, and remarks that Smith doesn't know that Neo and Trinity are trying to rescue Morpheus. Without the earpiece, Smith was no longer receiving intel on the humans, even though he should have been alerted immediately. This fits with the general principle that the Matrix programs are written to be as realistic as possible, even when it might seem counter-productive, because keeping the illusion intact is paramount. The Architect seems willing to even build in flaws to his program to avoid breaking the illusion.