A woman sentenced to 30 years in prison for shooting her boyfriend to death in 2014 has won a new trial after an appeals court found a problem with a jury instruction.

Virginia A. Vertetis, 57, was convicted on a first-degree murder in the shooting death of retired New York City cop Patrick Gilhuley in her Mount Olive home.

Vertetis claimed she acted in self-defense, but the jury didn’t buy that story and convicted her following a month-long trial in 2017.

The elementary school teacher testified over four days that she shot Gilhuley, 51, with his service weapon after he attacked her, while the prosecution countered that she was angry with the man for breaking up with her and killed him without provocation.

In her appeal, Vertetis argued that Superior Court Judge Stephen Taylor was mistaken when telling jurors that she had a duty to retreat if she was in danger and that this could derail her self-defense claim.

In fact, her attorney argued that she had no obligation to retreat under the “castle” doctrine, which says that deadly force is justified when defending yourself in your own home.

The appellate court agreed with that point.

“The (jury) charge not only omitted the ‘castle’ exception but expressly told the jurors — in no uncertain terms — that self-defense is not available to defendant if she could have safely retreated or was the initial aggressor. That mistake easily could have permeated the jury’s consideration of self-defense, not only with respect to the murder count but also the lesser-included homicide offenses," the appeals court wrote in its decision released Wednesday.

The appeals court vacated the murder conviction and ordered a new trial.

Vertetis is currently house in the Edna Mahan Correctional Facility in Union Township, where her parole eligibility date is March 2, 2044, according to prison records.

Virginia Vertetis walks into the courtroom before her sentencing in 2017.

Matt Gray may be reached at mgray@njadvancemedia.com. Follow him on Twitter @MattGraySJT. Find NJ.com on Facebook.

Have a tip? Tell us: nj.com/tips. Get the latest updates right in your inbox. Subscribe to NJ.com’s newsletters.