To access Office 365, there are some prerequisites that a client and the network the client is connected to must meet for Office 365 to work correctly.
TCP 443 - O365 Portal, Outlook, OWA, SharePoint
TCP 80/443 - Azure AD Sync Tool, Mail migration tools, Exchange.
TCP 25 - Mail Routing
TCP 587 - SMTP Relay
TCP 143/993 - IMAP Simple Migration Tool
TCP 995 - SPOP3
Further ports required by Lync
TCP 5223 - Lync Mobile clietn push notifications.
PSOM/TLS 443 - Lync Online outbound data sharing.
STUN/TCP 443 - Lync Online outbound audio, video, app sharing.
STUN/UDP 3478 - Lync Online outbound audio and video sessions.
UDP 20000-45000 - Lync to Phone outbound.
UDP 50000-59000 - Lync outbound audio and video sessions.
Office 365 Best Practices Analyzer - diagnose client connectivity. Requires Windows 7 SP1 (64Bit), IE9 onwards.
Access this from Tools menu in the O365 Admin center.
Office 365 OnRamp Tool - Check deployment readiness in on premises