[Argh]. I answered the wrong sub-question.
The harder case is for a non-parent to get custody from a parent: for one parent to prevail over the other given such a choice of environment would probably not be difficult (depending on the details of the alternative custody). In Washington state, RCW 26.10 is the chapter under which one would petition for non-parental custody. The statute is stunningly under-informative in terms of what counts: 26.10.100 simply says "The court shall determine custody in accordance with the best interests of the child". However, it is a possibility (which does not exist in all states).
To win the case over the parent's objection, one must either establish that the parent is unfit, or placing / leaving the child with that parent would have a negative effect – "being better" is not good enough. In re the Custody of Anderson, 77 Wn. App. 261 seems to a first piece of required reading on the topic (in this case, the mother retained custody, so it gives you an idea where the bar is). I don't know the final outcome of In re Stell, 56 Wn.App. 356, but in this case the aunt at least got to legal first base. In Stell, the court said
RCW 26.10.100 must be read to require more than the usual "best
interests" test. Thus, the trial court ruled that a parent has a
priority right to custody "unless the parent is either unfit or
placement of the child with the parent would detrimentally effect
[sic] the child's growth and development"
citing In re Marriage of Allen, 28 Wn.App. 637 ("The custody of the child may be awarded to the nonparent only upon a showing that the parent is unfit or that the child's growth and development would be detrimentally affected by placement with an otherwise fit parent"), Chapman v. Perera, 41 Wn.App. 444 ("giving custody to a parent would be detrimental to the child"). The crux of Stell is that the father was found to not be doing a good enough job of parenting, and the psychologist's testimony supported the aunt getting custody.
In these cases, nothing involved drug convictions or violent crimes. In re the Custody of Brown 153 Wn.2d 646 adds something on that front. The paternal grandmother Luby was taking care of the child (the parents had drug problems), but then Luby got busted for growing a respectable amount of marijuana, and did 30 days. The maternal grandmother Sherman subsequently witnessed a number of adults smoking the at-the-time illegal weed (2005), and now we have two competitors for non-parental custody. The trial court determined that Luby's household was a "threat to the child's well-being and continued exposure to the regular use of marijuana and abuse of alcohol is detrimental to the child" (this was upheld to the highest levels). This adds drug use in the home, but does not involve terminating a parent's custody, which is harder to do.
On the third or fourth hand, moving into a house occupied by people convicted of drug and violent crimes is not per se deleterious to a child's upbringing. The obvious question would be whether the people had paid their debt to society and were now virtuous, or were still engaged in bad behavior. There isn't any legal precedent in Washington for saying that moving into a house inhabited by reformed criminals is itself a harmful environment.