Facebook posted quarterly earnings and revenue that blew away analyst estimates as its ad business flourished.