Four people were killed, including a New York police officer, after a gunman opened fire in an office tower before fatally shooting himself, officials said.