We present a comprehensive study of polar and magnetic excitations in BiFeO3 ceramics and a thin film epitaxially grown on an orthorhombic (110) TbScO3 substrate. Infrared reflectivity spectroscopy was performed at temperatures from 5 to 900 K for the ceramics and below room temperature for the thin film. All 13 polar phonons allowed by the factor-group analysis were observed in theceramic samples. The thin-film spectra revealed 12 phonon modes only and an additional weak excitation, probably of spin origin. On heating towards the ferroelectric phase transition near 1100 K, some phonons soften, leading to an increase in the static permittivity. In the ceramics, terahertz transmission spectra show five low-energy magnetic excitations including two which were not previously known to be infrared active; at 5 K, their frequencies are 53 and 56 cm-1. Heating induces softening of all magnetic modes. At a temperature of 5 K, applying an external magnetic field of up to 7 T irreversibly alters the intensities of some of these modes. The frequencies of the observed spin excitations provide support for the recently developed complex model of magnetic interactions in BiFeO3 (R.S. Fishman, Phys. Rev. B 87, 224419 (2013)). The simultaneous infrared and Raman activity of the spin excitations is consistent with their assignment to electromagnons.