We can create a Feature Receiver were we can use the UpdateMappedPage method to define a custom access denied page.

Similarly, we can create custom pages for various events as shown in the below links: http://www.spdeveloper.co.in/articles/pages/custom-error-pages-for-sharepoint2010-sites.aspx

public class SPEventReceiver : SPFeatureReceiver
     {
         Const string AccessDeniedPage = "/_layouts/Pages/AccessDenied.aspx";
         public override void FeatureActivated(SPFeatureReceiverProperties properties)
         {
             SPWebApplication webapp = properties.Feature.Parent as SPWebApplication;
             if (webapp != null)
             {
                 if (!webapp.UpdateMappedPage(SPWebApplication.SPCustomPage.AccessDenied, AccessDeniedPage)
                 {
                     throw new ApplicationException("Cannot create the new Access Denied Page Mappings.");
                 }
                 webapp.Update(true);
             }
         }
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
         {
             SPWebApplication webapp = properties.Feature.Parent as SPWebApplication;
             if (webapp != null)
             {
                 if (!webapp.UpdateMappedPage(SPWebApplication.SPCustomPage.AccessDenied, null))
                 {
                     throw new ApplicationException("Cannot reset the default Access Denied Page Mappings.");
                 }
                 webapp.Update(true);
             }
         }
      }