CVS Health on Wednesday said it had agreed to a $5 billion settlement designed to "substantially resolve" opioid lawsuits against the pharmacy chain.