There are two ways to do this, and they work really well:
1- Using JavascriptExecutor
((JavascriptExecutor) driver).executeScript("window.alert = function(msg){};");
((JavascriptExecutor) driver).executeScript("window.confirm = function(msg){return true;};");
2- Using PhantomJS callbacks (you need the 1.1.0 version of GhostDriver to do this)
PhantomJSDriver phantom = (PhantomJSDriver) driver;
phantom.executePhantomJS("var page = this;" +
"page.onAlert = function(msg) {" +
"console.log('ALERT: ' + msg);" +
"};");
phantom.executePhantomJS("var page = this;" +
"page.onConfirm = function(msg) {" +
"console.log('CONFIRM: ' + msg);"
"return true;" +
"};");