The simultaneous recording of EEG and fMRI is a promising method for combining the electrophysiological and hemodynamic information on cerebral dynamics. However, EEG recordings performed in the MRI scanner are contaminated by imaging, ballistocardiographic (BCG) and ocular artifacts. A number of processing techniques for the cancellation of fMRI environment disturbances exist: the most popular is averaged artifact subtraction (AAS), which performs well for the imaging artifact, but has some limitations in removing the BCG artifact, due to the variability in cardiac wave duration and shape; furthermore, no processing method to attenuate ocular artifact is currently used in EEG/fMRI, and contaminated epochs are simply rejected before signal analysis. In this work, we present a comprehensive method based on independent component analysis (ICA) for simultaneously removing BCG and ocular artifacts from the EEG recordings, as well as residual MRI contamination left by AAS. The ICA method has been tested on event-related potentials (ERPs) obtained from a visual oddball paradigm: it is very effective in attenuating artifacts in order to reconstruct clear brain signals from EEG acquired in the MRI scanner. It performs significantly better than the AAS method in removing the BCG artifact. Furthermore, since ocular artifacts can be completely suppressed, a larger number of trials is available for analysis. A comparison of ERPs inside the magnetic environment with those obtained out of the MRI scanner confirms that no systematic bias in the ERP waveform is produced by the ICA method.