Hershey beat fourth-quarter profit and sales estimates as the chocolate maker's price hikes helped offset the higher cost of cocoa.