This interesting phrase has changed its meaning over the years. Back in 1473, according to the Oxford English Dictionary, it simply meant a product or something manufactured. By 1533, it was also being used to mean a difficult undertaking or task. Shakespeare used it in a very positive way in Hamlet (1604):
“What a piece of work is a man, how noble in reason, how infinite in faculties, in form and moving how express and admirable, in action how like an angel, in apprehension how like a god!”
The expression was first used in a derogatory way in 1713. The first published reference is from the manuscripts of the Duke of Portland:
“I believe your Lordship will have nothing to do with him he being a whidling, dangerous, piece of work and not to be trusted.” Quite often, when the phrase was used in a dismissive fashion, it would be expanded to “a nasty piece of work.”
Even as late as the 1950s, British novelist Angela Thirkell used the phrase in a positive way. One of her characters, a lover of powerful cars, is looking under the hood of a big luxurious automobile, and when he straightens, he says in admiration, “By Jove! It is a piece of work.”
Nowadays, the phrase most often means someone who is difficult to get along with on a day to day basis. Such people often have strong personalities, and may also have seriously unpleasant character flaws.
However, this use of the phrase is considered colloquial or informal, so we usually see it only in comments on news articles from cranky readers, or hear it from friends complaining about their day at work.
It is far more common to find “piece of work,” used in print, in the more standard sense of “a product of work” or a work of art or literature. This from Virginia Woolf, in 1915: “She was indeed very proud that she had finished her book… Also she thought that it was a good piece of work.”
Back in the day, you had to use adjectives (such as “nasty”) before “piece of work,” in order to convey the desired negative meaning, but in these later years, the plain, unadorned “piece of work” applied to a person is regarded as negative. Today we assume that the person described as a “piece of work” is not being compared, as in Hamlet, to an angel.
I realize that I use the phrase in both senses: to refer in a scornful way to somebody who annoys me, but also in a positive sense to something I’ve written, as a novel or short story. Context is everything!