From the MCU we learn that Asgardians live a lot longer than humans. Loki mentions it to be something like 3000 years on average. So it's safe to say that all the Asgardians we see in the first Thor movie were alive during world war 2, when HYDRA used the Tesseract to power their weapons. Couldn't Heimdall see what was happening and alert Odin that an EXTREMELY powerful artefact (which he lost) is in the possession of humans? Furthermore, why didn't the Asgardian army intervene? There was an INFINITY STONE in play!!! When does Odin think it appropriate to send his army? 'Cause at that time the Bifrost wasn't broken like in the first Avengers movie where he could have sent in his army to fight the Chitauri.
TL;DR: It doesn't work like that - Heimdall is not aware of everything going on at all times. He must actively look or listen for something to notice it.
You are under the false assumption that Heimdall is always aware of everything going on at all times, which is simply not the way his abilities work. Rather, Heimdall has the ability to see and/or hear anything within The Nine Realms when he focuses on it.
Heimdall's role within the Asgardian pantheon is The Bifrost Guardian. Essentially, he is the guy who guards the Rainbow Bridge, which is basically the front door to Asgard. To make him a more efficient guardsman, Odin bestowed upon him the gift of sight, meaning the ability to see any threat before it reaches Asgard. Given that Heimdall has failed in his role on at least two occasions, we know that neither he nor his sight is infallible.
To answer your question more specifically, we know that the MCU version of Heimdall must indeed focus his attention on something or someone to see what they're up to. We see this aspect of his abilities in Thor: The Dark World:
THOR: [laughs] Perhaps. How fare the stars?
HEIMDALL: Still shining. From here I can see nine realms and ten trillion souls.
[Heimdall drives his sword into the control panel in the center of the observatory. He looks to Thor.]
HEIMDALL: You recall what I told you of the Convergence?
THOR: Yes. The alignment of the worlds. It approaches, doesn’t it?
HEIMDALL: The universe hasn’t seen this marvel since before my watch began. Few can sense it, even fewer can see it. But while it’s effects can be dangerous, it is truly beautiful.
THOR: [gazes at the stars] I see nothing.
HEIMDALL: Or perhaps, that is not the beauty you seek?
THOR: [laughs for a moment] How is she?
HEIMDALL: She’s quite clever, your mortal. She doesn’t know it yet, but she studies the Convergence as well. [Turns his gaze out towards some distant sight] Even... [stares into nothing]
HEIMDALL: I can’t see her.
In regards to the Tesseract, Heimdall has no reason to focus his attention on it. As far as the Asgardians know, the Tesseract is safely hidden away in a monastery on Midgard - the same place it's been for the past thousand years or more.
Despite the Human notion the Asgardians are gods, Heimdall is neither omniscient nor omnipotent. His vaunted super-senses, while capable of amazing range, precision and accuracy require both his attention and focus. And while he can sense things at great distances, he is not able to absorb all of the events in the universe simultaneously and process them like a giant god-like supercomputer.
- As I have already mentioned, his powers are a native magic of his people, the Vanir. (See: Where does Heimdall's sight come from?) His senses appear to act as a form of super-clairvoyance. He can hear and see anything he focuses his senses on, assuming a more powerful magic or technology is not shielding them. His range is phenomenal, he is able to reach all the way to the Lesser Magellenic Cloud where the Kree Empire is centered (over 200,000 light years away...)
In the story, entitled "When Heimdall Failed!", the King of the Storm Giants sends a Vanna - a fairy-like creature so tiny and insubstantial it can be neither seen nor heard - to spy on the denizens of the godly realm.
And yet mighty Heimdall's senses are so attuned that he can tell something is amiss - that something has passed him by at his vigilant post - and so he rushes to the royal chambers where the creature has made its way. By invoking the Odinpower, Asgard's ruler is able to pluck the creature from the air and punish it accordingly, at which point Heimdall lays himself down to receive his own grave consequence for having let the winged sprite by.
Instead, Odin congratulates him, pointing out not just his heightened sense but his commitment to sound the alarm, despite lacking evidence of any kind. By the vignette's end, Heimdall is standing watch on the Rainbow Bridge once again.... REF: Journey into Mystery #105, 1964
He does not see the origin of things, so he might be able to see World War II for example, have seen Hydra agents using energy weapons and thought nothing more of it. Considering he is constantly on the look out across the Nine Realms, he is aware of trillions of souls and dozens of planets, with hostile civilizations far more advanced than Earth.
He doesn't keep track of their history, per se. He notes their wars or occasional technologies, in case they may threaten the Realm Eternal, but beyond that, if it doesn't affect them directly, they are ignored. Knowing Hydra, they made ever effort to keep the Tesseract under lock and key and perhaps any potential surveillance.
He appears to be able to see and target individuals or objects he is familiar with and has had a reason to look for in the first place. Consider it a form of quantum entanglement. Once he has looked for you, he can always look for you, assuming his senses can reach that place. He is instantly able to locate Jane Foster once he knew who she was.
Objects like the Tesseract, which have incredible powers in their own right may be able to make themselves, or are inherently, proof against such detection magic. We don't know if Heimdall even knew it existed, had ever been entangled with it, before the events of the movie, so he wouldn't have known to look for this singular object, which might have been capable of cloaking itself, from the hundreds of trillions of potentially powerful and diverse alien technologies across the Nine Worlds.
Knowing Odin as a secretive type, he may have never let anyone know about the Tesseract's ultimate loss, for fear it might spur technologically advanced people to go looking for it. Being lost on Earth wasn't the worst thing for it, considering when it was lost we were still banging swords together in the Middle Ages.
It also meant no one would go looking for it on Earth, since Earth was near the edge of the galaxy and out of the way of most of the larger stellar empires. "Security by obscurity" was likely Odin's play. Anyone powerful enough to look for it, find it and use it would bring it to Heimdall's attention.
I can think of three factors that are at play here:
Odin of the MCU seems to have a pretty hands-off approach to the Nine Realms. He negotiates with the Frost Giants even when they attack him, he refuses to help heal Jane Foster even when Thor brings her to Asgard. Whether that makes him "soft" is a matter of opinion (Loki would say yes, Thor would say no), but it's undeniable that he's very aloof.
2) Lack of Awareness
Heimdall sees a lot when he just passively gazes out into the universe, but it's well-established that some details escape his notice until he really looks for them. Heimdall would undoubtedly have been aware of World War 2, but are we sure he knew about the specific source of the Hydra technology?
I could easily imagine Heimdall at his post, thinking to himself, "Interesting, the humans have developed lasers earlier than I would have expected. These German folk are resourceful, I see now why Odin gave them his favor," and then moving on without making the connection to the Tesseract.
This is re-inforced by the post-credits scene in which Loki "discovers" that the Tesseract is in SHIELD's possession. His reaction certainly seems like he didn't know it had been found, which would imply that Odin might not, as well.
3) Maybe, a different idea of what constitutes a threat?
This one's going to be the most controversial, but personally it makes sense to me. Basically, Infinity Stones, we're shown again and again, display varying levels of power based on the user. Malekith could use the Aether in ways Jane Foster couldn't, Peter Quill could survive holding and using the Power Stone for far longer than Ronin could have, and Vision is both more benevolent and more capable with the Mind Stone than Ultron was.
It's entirely possible that, even if Odin knew about the Tesseract being used as a weapon on Earth, he simply didn't consider it worth intervening. Maybe if Red Skull's plan to start wiping out continents had been successful, he might have found a golden-armored legion at his doorstep. But Red Skull was basically using the Tesseract as a battery, and little else. Yeah, he was a conqueror, but who cares? Odin doesn't get involved in human politics, so the fact that Hydra was "evil" wouldn't have registered. Red Skull was an upstart who'd barely conquered one continent of Midgard, and had barely found the Tesseract's on-switch.
If the Aether could be considered safe in the vaults of a glorified art dealer, maybe Odin considered the Tesseract safe in the halls of Earth's latest warlord?