Cosmological dynamics and dark energy from nonlocal infrared modifications of gravity